package pkg.chemdrm;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public class DoorSprite extends AnimatedSprite implements Entity {
	float mLifetime = 0;
	float mDeathBegin = 0;
	boolean mDeath = false;
	
	public DoorSprite(AIRegion pRegion, TiledTextureRegion pTiledTextureRegion) 
	{	
		super(pRegion.getX(), pRegion.getY(), 100, 100, pTiledTextureRegion);
		this.mScaleX = (pRegion.getWidth() / this.getWidth());
		this.mScaleY = (pRegion.getHeight() / this.getHeight());
	}
	
	public void update(float dt)
	{
		mLifetime += dt;
		if(mDeath)
		{
			if(mLifetime - mDeathBegin >= 2.9)
			{
				detachSelf();
				this.setVisible(false);
			}
			
		}
		
	}
	
	public void destroySelf()
	{
	
		if(!mDeath)
		{
			this.animate(1000);
			mDeathBegin = mLifetime;
			mDeath = true;
		}
		
	}

	public boolean getExists() {
		return this.isVisible();
	}

}
